//
//  An_uiviewBlockViewController.m
//  Animation_UIview1
//
//  Created by 刘文超 on 2019/12/24.
//  Copyright © 2019 刘文超. All rights reserved.
//

#import "An_uiviewBlockViewController.h"

@interface An_uiviewBlockViewController ()
@property(nonatomic,strong)UIImageView *ls_imageView1;
@property(nonatomic,strong)UIImageView *ls_imageView2;
@end

@implementation An_uiviewBlockViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    
//    [UIView animateWithDuration:(NSTimeInterval) // 动画执行时间
//                          delay:(NSTimeInterval) // 延迟时间
//                        options:UIViewAnimationOptions)  // 动画的效果
//                     animations:^{
//                         // 你的code
//                     } completion:^(BOOL finished) {
//                         // 动画执行完成
//                     }];
    /*
    UIViewAnimationOptionLayoutSubviews            //进行动画时布局子控件
    UIViewAnimationOptionAllowUserInteraction      //进行动画时允许用户交互
    UIViewAnimationOptionBeginFromCurrentState     //从当前状态开始动画 UIViewAnimationOptionRepeat                    //无限重复执行动画
    UIViewAnimationOptionAutoreverse               //执行动画回路
    UIViewAnimationOptionOverrideInheritedDuration //忽略嵌套动画的执行时间设置
    UIViewAnimationOptionOverrideInheritedCurve    //忽略嵌套动画的曲线设置 UIViewAnimationOptionAllowAnimatedContent      //转场：进行动画时重绘视图
    UIViewAnimationOptionShowHideTransitionViews   //转场：移除（添加和移除图层的）动画效果
    UIViewAnimationOptionOverrideInheritedOptions  //不继承父动画设置
    
    UIViewAnimationOptionCurveEaseInOut            //时间曲线，慢进慢出（默认值）
    UIViewAnimationOptionCurveEaseIn               //时间曲线，慢进
    UIViewAnimationOptionCurveEaseOut              //时间曲线，慢出
    UIViewAnimationOptionCurveLinear               //时间曲线，匀速
    
    UIViewAnimationOptionTransitionNone            //转场，不使用动画
    UIViewAnimationOptionTransitionFlipFromLeft    //转场，从左向右旋转翻页
    UIViewAnimationOptionTransitionFlipFromRight   //转场，从右向左旋转翻页
    UIViewAnimationOptionTransitionCurlUp          //转场，下往上卷曲翻页
    UIViewAnimationOptionTransitionCurlDown        //转场，从上往下卷曲翻页
    UIViewAnimationOptionTransitionCrossDissolve   //转场，交叉消失和出现
    UIViewAnimationOptionTransitionFlipFromTop     //转场，从上向下旋转翻页
    UIViewAnimationOptionTransitionFlipFromBottom  //转场，从下向上旋转翻页
     */
    
//    UIView *bgView=[[UIView alloc]initWithFrame:CGRectMake(100, 100, 100, 100)];
//    [self.view addSubview:bgView];
//    bgView.backgroundColor= [UIColor redColor];
    
    
    //1.普通的
//    [UIView animateWithDuration:3 delay:2 options:UIViewAnimationOptionTransitionFlipFromLeft animations:^{
//        bgView.frame = CGRectMake(150, 200, 100, 100);
//    } completion:^(BOOL finished) {
//          bgView.frame = CGRectMake(100, 100, 100, 100);
//    }];
    
    
    //2.关键帧动画
    // 关键帧动画
//    UIViewAnimationOptionLayoutSubviews           //进行动画时布局子控件
//    UIViewAnimationOptionAllowUserInteraction     //进行动画时允许用户交互
//    UIViewAnimationOptionBeginFromCurrentState    //从当前状态开始动画
//    UIViewAnimationOptionRepeat                   //无限重复执行动画
//    UIViewAnimationOptionAutoreverse              //执行动画回路
//    UIViewAnimationOptionOverrideInheritedDuration //忽略嵌套动画的执行时间设置
//    UIViewAnimationOptionOverrideInheritedOptions //不继承父动画设置
//
//    UIViewKeyframeAnimationOptionCalculationModeLinear     //运算模式 :连续
//    UIViewKeyframeAnimationOptionCalculationModeDiscrete   //运算模式 :离散
//    UIViewKeyframeAnimationOptionCalculationModePaced      //运算模式 :均匀执行
//    UIViewKeyframeAnimationOptionCalculationModeCubic      //运算模式 :平滑
//    UIViewKeyframeAnimationOptionCalculationModeCubicPaced //运算模式 :平滑均匀
//    [UIView animateKeyframesWithDuration:4.0 delay:0.f options:UIViewKeyframeAnimationOptionCalculationModeDiscrete animations:^{
//        //新建关键帧
//        [UIView addKeyframeWithRelativeStartTime:0.f relativeDuration:1.0 / 4 animations:^{
//            bgView.backgroundColor = [UIColor colorWithRed:0.9475 green:0.1921 blue:0.1746 alpha:1.0];
//        }];
//        //新建关键帧
//        [UIView addKeyframeWithRelativeStartTime:1.0 / 4 relativeDuration:1.0 / 4 animations:^{
//            bgView.backgroundColor = [UIColor colorWithRed:0.1064 green:0.6052 blue:0.0334 alpha:1.0];
//        }];
//        //新建关键帧
//        [UIView addKeyframeWithRelativeStartTime:2.0 / 4 relativeDuration:1.0 / 4 animations:^{
//            bgView.backgroundColor = [UIColor colorWithRed:0.1366 green:0.3017 blue:0.8411 alpha:1.0];
//        }];
//        //新建关键帧
//        [UIView addKeyframeWithRelativeStartTime:3.0 / 4 relativeDuration:1.0 / 4 animations:^{
//            bgView.backgroundColor = [UIColor colorWithRed:0.619 green:0.037 blue:0.6719 alpha:1.0];
//        }];
//    } completion:^(BOOL finished) {
//        NSLog(@"动画结束");
//    }];
    
    UIImageView * newCenterShow = [[UIImageView alloc]initWithFrame:CGRectMake(100,100 , 100, 100)];
//    newCenterShow.image = [UIImage imageNamed:@"logo"];
    newCenterShow.backgroundColor = [UIColor orangeColor];
    [self.view addSubview:newCenterShow];
    self.ls_imageView2 = newCenterShow;
    
    
    
    UIImageView *logoImageView=[[UIImageView alloc]initWithFrame:CGRectMake(100, 200, 100, 100)];
    [self.view addSubview:logoImageView];
//    logoImageView.image = [UIImage imageNamed:@"zpb.jpg"];
    logoImageView.contentMode=UIViewContentModeScaleAspectFill;
    logoImageView.clipsToBounds=YES;
    logoImageView.backgroundColor = [UIColor yellowColor];
    self.ls_imageView1 = logoImageView;
    
  
  
}

-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
//    [self ls_zhuanchangAnimation];
    [self ls_zhengAnimation];
    
}
#pragma mark --普通动画
-(void)ls_nomerAnimation
{
    [UIView animateWithDuration:2 delay:1 options:UIViewAnimationOptionCurveEaseOut animations:^{
          self.ls_imageView2.image = [UIImage imageNamed:@"zpb.jpg"];
    } completion:^(BOOL finished) {
        
    }];
    
}
#pragma mark --转场动画
-(void)ls_zhuanchangAnimation
{

    //@1 从旧识图转到新试图
    // 从旧视图转到新视图的动画效果
    //注意s代码执行顺序
//    [UIView transitionFromView:self.ls_imageView1 toView:self.ls_imageView2 duration:1.0 options:UIViewAnimationOptionTransitionFlipFromLeft completion:^(BOOL finished) {
//        NSLog(@"动画结束");
//    }];
    
    
     // @2单个视图的过渡效果
        [UIView transitionWithView:self.ls_imageView2 duration:3.0 options:UIViewAnimationOptionTransitionFlipFromLeft animations:^{
            self.ls_imageView2.image = [UIImage imageNamed:@"zpb.jpg"];
        } completion:^(BOOL finished) {
            NSLog(@"动画结束");
        }];
}
#pragma mark -- 关键帧动画
-(void)ls_zhengAnimation
{
    [UIView animateKeyframesWithDuration:5 delay:1 options:UIViewKeyframeAnimationOptionCalculationModeCubicPaced animations:^{
        //开始时间 持续时间 期间做的事
        [UIView addKeyframeWithRelativeStartTime:0.f relativeDuration:1.0/5 animations:^{
            self.ls_imageView1.frame = CGRectMake(200, 200, 100, 100);
            self.ls_imageView2.backgroundColor = [UIColor redColor];
            
        }];
        [UIView addKeyframeWithRelativeStartTime:1.0/5 relativeDuration:2.0/5 animations:^{
            self.ls_imageView1.frame = CGRectMake(200, 300, 100, 100);
            self.ls_imageView2.backgroundColor = [UIColor blueColor];
            
        }];
        [UIView addKeyframeWithRelativeStartTime:3.0/5 relativeDuration:1.0/5 animations:^{
            self.ls_imageView1.frame = CGRectMake(400, 150, 100, 100);
            self.ls_imageView2.backgroundColor = [UIColor greenColor];
            
        }];
        [UIView addKeyframeWithRelativeStartTime:4.0/5 relativeDuration:0.5/5 animations:^{
            self.ls_imageView1.frame = CGRectMake(150, 300, 50, 50);
            self.ls_imageView2.backgroundColor = [UIColor blackColor];
            
        }];
        [UIView addKeyframeWithRelativeStartTime:4.5/5 relativeDuration:0.5/5 animations:^{
            self.ls_imageView1.frame = CGRectMake(200, 350, 100, 100);
            self.ls_imageView2.backgroundColor = [UIColor purpleColor];
            
        }];
        
    } completion:^(BOOL finished) {
        NSLog(@"完成");
    }];
    
}
@end
